package com.zib.bilibili.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.zib.bilibili.R;
import com.zib.bilibili.bean.TuijianBean;
import com.zib.bilibili.utils.ImageLoader;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import de.hdodenhof.circleimageview.CircleImageView;

/**
 * ----------BigGod be here!----------/
 * ***┏┓******┏┓*********
 * *┏━┛┻━━━━━━┛┻━━┓*******
 * *┃             ┃*******
 * *┃     ━━━     ┃*******
 * *┃             ┃*******
 * *┃  ━┳┛   ┗┳━  ┃*******
 * *┃             ┃*******
 * *┃     ━┻━     ┃*******
 * *┃             ┃*******
 * *┗━━━┓     ┏━━━┛*******
 * *****┃     ┃神兽保佑*****
 * *****┃     ┃代码无BUG！***
 * *****┃     ┗━━━━━━━━┓*****
 * *****┃              ┣┓****
 * *****┃              ┏┛****
 * *****┗━┓┓┏━━━━┳┓┏━━━┛*****
 * *******┃┫┫****┃┫┫********
 * *******┗┻┛****┗┻┛*********
 * ━━━━━━神龙出没━━━━━━
 * <p/>
 * 项目名称：@string/app_name
 * 类描述：
 * 创建人：jackie
 * 创建时间：2016/7/10
 * 修改人：jackie
 * 修改时间：2016/7/10
 * 修改备注：
 */
public class TuijianGridViewAdapter extends BaseAdapter {
    private Context context = null;
    private List<TuijianBean.ResultBean.BodyBean> list = null;
    private LayoutInflater inflater = null;

    public TuijianGridViewAdapter(Context context, List<TuijianBean.ResultBean.BodyBean> list) {
        this.context = context;
        this.list = list;
        inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder mHolder=null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_gridviewitem_live, parent, false);
            mHolder=new ViewHolder(convertView);
            convertView.setTag(mHolder);
        }else {
            mHolder= (ViewHolder) convertView.getTag();
        }

        ImageLoader.getInstance().displayImage(context, list.get(position).getCover(), mHolder.imageViewLiveImage);
        String title = list.get(position).getTitle()+"";
        if (title.length()>7){
            title=title.substring(0,7)+"...";
        }
        mHolder.textViewLiveUsername.setText(title);
        String play = list.get(position).getPlay()+"";
        if (play!=null){
            mHolder.textViewLiveCount.setText(list.get(position).getPlay() + "");
        }else {
            mHolder.textViewLiveCount.setVisibility(View.GONE);
        }

        mHolder.textViewLiveTitle.setText(list.get(position).getDanmaku());

        String up_face = list.get(position).getUp_face()+"";
        if (up_face != null) {
            ImageLoader.getInstance().displayImage(context,up_face,mHolder.imageViewLiveIcon);
        }else {
            mHolder.imageViewLiveIcon.setVisibility(View.GONE);
        }







        return convertView;
    }

    public class ViewHolder {
        @Bind(R.id.imageView_live_image)
        ImageView imageViewLiveImage;
        @Bind(R.id.imageView_live_icon)
        CircleImageView imageViewLiveIcon;
        @Bind(R.id.textView_live_username)
        TextView textViewLiveUsername;
        @Bind(R.id.textView_live_count)
        TextView textViewLiveCount;
        @Bind(R.id.textView_live_title)
        TextView textViewLiveTitle;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
